<?php

namespace app\admin\model\xykeep\delivery;

use think\Model;
use traits\model\SoftDelete;

class Storetake extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'xykeep_delivery_storetake';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'expire_type_text',
        'expire_time_text'
    ];
    

    
    public function getExpireTypeList()
    {
        return ['day' => __('Expire_type day'), 'time' => __('Expire_type time')];
    }


    public function getExpireTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['expire_type']) ? $data['expire_type'] : '');
        $list = $this->getExpireTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getExpireTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['expire_time']) ? $data['expire_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setExpireTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
